package com.dlsy.ygj.dao.vindicateData.impl;

import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.dlsy.ygj.dao.vindicateData.IGoodsInfoDAO;
import com.dlsy.ygj.entity.GoodsInfo;
import com.dlsy.ygj.entity.MainItemInfo;

import net.taobaoge.common.framework.dao.impl.BaseDAOImpl;

public class GoodsInfoDAO extends BaseDAOImpl<GoodsInfo> implements
		IGoodsInfoDAO {

	@SuppressWarnings("unchecked")
	public List<GoodsInfo> findGoodsByIds(final Collection<Integer> conns) {
		return getHibernateTemplate().executeFind(new HibernateCallback() {

			public List<GoodsInfo> doInHibernate(Session session)
					throws HibernateException, SQLException {
				Query query = session
						.createQuery("From GoodsInfo g Where g.goodsInfoId in (:condtion)");
				query.setParameterList("condtion", conns);
				List<GoodsInfo> goods = query.list();
				if (goods != null && goods.size() > 0) {
					return goods;
				}
				return null;
			}
		});
	}

	public List<GoodsInfo> findByName(int id, String keyword) {
		System.out.println("sss");
		System.out.println(keyword+"keyword");
		List<GoodsInfo> goodsInfoList1 = this.findByHql(
				"from GoodsInfo h where h.storefrontId=? and h.goodsNo like ?",
				id, keyword);
		List<GoodsInfo> goodsInfoList2 = this
				.findByHql(
						"from GoodsInfo h where h.storefrontId=? and  h.goodsName like ?",
						id, keyword);
		List<GoodsInfo> goodsInfoList3 = this.findByHql(
				"from GoodsInfo h where h.storefrontId=? and h.spell like ?",
				id, keyword);
		if (goodsInfoList1.size() > 0) {
  System.out.println("11111111111111111111111");
			return goodsInfoList1;

		}
		if (goodsInfoList2.size() > 0) {
      System.out.println("ssssssssssssssssssssssssssssssssssssss");
			return goodsInfoList2;

		}
		if (goodsInfoList3.size() > 0) {
System.out.println("44444444444444444444444444444444");
			return goodsInfoList3;

		}

		return null;
	}

}
